// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLStatement;
// import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
// import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
// import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStatementImpl;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "MySqlCaseStatement.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLObject.h"
#include "../../../../ast/SQLStatement.h"
#include "../../../../ast/statement/SQLIfStatement.h"
#include "../../visitor/MySqlASTVisitor.h"
#include "../../../../../utils/listTran.h"

MySqlCaseStatement_MySqlWhenStatement::MySqlCaseStatement_MySqlWhenStatement()
{
  statements = std::make_shared<std::list<SQLStatement_ptr>>();
}
// @Override
void MySqlCaseStatement_MySqlWhenStatement::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlCaseStatement_MySqlWhenStatement)))
  {
    acceptChild(visitor, condition);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLStatement, SQLObject>(statements);
    acceptChild(visitor, tmp1);
  }
  visitor->endVisit(SharedObject(MySqlCaseStatement_MySqlWhenStatement));
}

SQLExpr_ptr MySqlCaseStatement_MySqlWhenStatement::getCondition()
{
  return condition;
}

void MySqlCaseStatement_MySqlWhenStatement::setCondition(SQLExpr_ptr condition)
{
  this->condition = condition;
}

SQLStatement_list_ptr MySqlCaseStatement_MySqlWhenStatement::getStatements()
{
  return statements;
}

void MySqlCaseStatement_MySqlWhenStatement::setStatements(SQLStatement_list_ptr statements)
{
  this->statements = statements;
}

MySqlCaseStatement::MySqlCaseStatement()
{
  whenList = std::make_shared<std::list<MySqlCaseStatement_MySqlWhenStatement_ptr>>();
}

SQLExpr_ptr MySqlCaseStatement::getCondition()
{
  return condition;
}

void MySqlCaseStatement::setCondition(SQLExpr_ptr condition)
{
  this->condition = condition;
}

MySqlCaseStatement_MySqlWhenStatement_list_ptr MySqlCaseStatement::getWhenList()
{
  return whenList;
}

void MySqlCaseStatement::setWhenList(MySqlCaseStatement_MySqlWhenStatement_list_ptr whenList)
{
  this->whenList = whenList;
}

void MySqlCaseStatement::addWhenStatement(MySqlCaseStatement_MySqlWhenStatement_ptr stmt)
{
  this->whenList->push_back(stmt);
}

SQLIfStatement_Else_ptr MySqlCaseStatement::getElseItem()
{
  return elseItem;
}

void MySqlCaseStatement::setElseItem(SQLIfStatement_Else_ptr elseItem)
{
  this->elseItem = elseItem;
}

// @Override
void MySqlCaseStatement::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlCaseStatement)))
  {
    acceptChild(visitor, condition);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<MySqlCaseStatement_MySqlWhenStatement, SQLObject>(whenList);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, elseItem);
  }
  visitor->endVisit(SharedObject(MySqlCaseStatement));
}

// @Override
SQLObject_list_ptr MySqlCaseStatement::getChildren()
{
  SQLObject_list_ptr children = std::make_shared<std::list<SQLObject_ptr>>();
  // children.addAll(children);
  // children.addAll(whenList);
  // children.addAll(whenList);
  for (auto it : *whenList)
  {
    children->push_back(it);
  }
  
  if (elseItem != nullptr)
  {
    children->push_back(elseItem);
  }
  return children;
}
